package com.mindether.llyblog.controller;

import com.mindether.llyblog.hanlder.ExceptionHanlder;
import com.mindether.llyblog.pojo.Tag;
import com.mindether.llyblog.service.TagService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

//@Controller
//@RequestMapping({"${server.error.path:${error.path:/error}}"})
public class CustomErrorController implements ErrorController{
    private static final Logger log= LoggerFactory.getLogger(ExceptionHanlder.class);

    @Autowired
    private TagService tagService;
    @RequestMapping
    public String handle404Error(Model model){
        List<Tag> tags=ArticleController.allTags;
        model.addAttribute("allTags",ArticleController.allTags);
        log.error("出现错误，详细信息为：访问不存在的页面");
        return "/error";
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
